package com.ly.jvm.oom.memoryleak.single;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @Classname FileOperator
 * @Description TODO
 * @Date 2020/9/26 18:34
 * @Author 冷心影翼
 */
public class Test {

    public static void main(String[] args) {
        ServiceB serviceB = new ServiceB();
        serviceB.setList();

        ServiceA serviceA = new ServiceA();
        serviceA.f();
    }
}

class ServiceA {

    public void f() {
        HashMap<String,byte[]> map = new HashMap<>();
        map.put("A",new byte[1024*1024*30]);  //30m
        map.put("B",new byte[1024*1024*30]);  //60m
        map.put("C",new byte[1024*1024*30]);  //90m
        map.put("D",new byte[1024*1024*30]);
        map.put("E",new byte[1024*1024*30]);
    }

}


class ServiceB {

    public void setList() {
        ArrayList<byte[]> list = new ArrayList<>(1000);
        insert(list);
        Single.getInstance().list = list;
        System.out.println("---");
    }

    public void insert(List list) {
        //100MB
        for (int i = 0; i < 300; i++) {
            //1MB
            byte[] b = new byte[1024*1024];
            list.add(b);

        }
    }
}


